package stage1.module3.homework4;

import java.awt.desktop.SystemEventListener;
import java.util.ArrayList;
import java.util.Scanner;

public class Add {
    public Add(ArrayList<Student> students){
        //先判断学号是否重复，若重复则需要重新输入，若不重复则继续输入其他信息
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        int id = 0;
        //判断学号是否重复
        while (flag){
            flag = false;
            System.out.println("请输入学号");
            id = sc.nextInt();
            for(Student s : students){
                if(s.getId() == id){
                    System.out.println("已有存在该学号，请重新输入");
                    flag = true;
                    break;
                }
            }
        }
        System.out.println("请输入姓名");
        String name = sc.next();
        System.out.println("请输入年龄");
        int age = sc.nextInt();
        students.add(new Student(id, name, age));
    }
}
